package com.cet;

import java.util.concurrent.TimeUnit;

public class Main {

    private static boolean flag = true;

    public static void main(String[] args) {

        new Thread(() -> {
            while (flag){

            }
            System.out.println(Thread.currentThread().getName() + "退出循环");
        }).start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        flag = false;
        System.out.println(Thread.currentThread().getName() + "将flag改为flase");
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main线程结束");
    }
}
